package com.epam.tcs.actions;

import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BreadCrumb {

	private String caption;
	private String url;
	
	
	private BreadCrumb(String caption, String url) {
		this.caption = caption;
		this.url = url;
	}
	
	public static void add(HttpServletRequest req, HttpServletResponse res, String caption, String url){
		
		List<BreadCrumb> breadcrumbs;
		String delimiter = "| ";
		
		if (req.getAttribute("breadcrumbs") != null) {
			breadcrumbs = (List<BreadCrumb>) req.getAttribute("breadcrumbs");
			breadcrumbs.add(new BreadCrumb(delimiter + caption,url));
		} else {
			breadcrumbs = new LinkedList<BreadCrumb>();
			breadcrumbs.add(new BreadCrumb(caption,url));
		}		
		
		req.setAttribute("breadcrumbs", breadcrumbs);
	}
	
	public String getCaption() {
		return caption;
	}
	public void setCaption(String caption) {
		this.caption = caption;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	
	
}
